package com.nuoniu.sibanyun.controller.erp;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpCurrencyAccount;
import com.nuoniu.sibanyun.service.erp.IErpCurrencyAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 币种记账详情 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-10-13
 */
@RestController
@RequestMapping("/erp/currencyAccount")
@Api(tags = "币种记账详情")
public class ErpCurrencyAccountController extends BaseController {

    @Autowired
    private IErpCurrencyAccountService currencyAccountService;

    @GetMapping("pageList")
    @ApiOperation("获取列表")
    public HttpResult pageList(Page page, ErpCurrencyAccount currencyAccount) {
        Page<ErpCurrencyAccount> currencyAccountPage = currencyAccountService.pageList(page, currencyAccount);
        return HttpResult.ok(currencyAccountPage);
    }

    @PostMapping("save")
    @ApiOperation("保存")
    public HttpResult save(@RequestBody ErpCurrencyAccount currencyAccount) {
        if(currencyAccount.getCurrencyId() == null) {
            throw new NuoNiuException("币种id不能为空");
        }
        if(currencyAccount.getYear() == null) {
            throw new NuoNiuException("年份不能为空");
        }

        currencyAccountService.saveOrUpdate(currencyAccount);
        return HttpResult.ok();
    }
}
